Skip to content

SDK-470 Add CustomDebugStringConvertible to AuthFailureReason#1073

Merged
sumeruchat merged 2 commits into
masterfrom
fix/SDK-470-authfailurereason-debug-string
Jun 12, 2026
Merged

SDK-470 Add CustomDebugStringConvertible to AuthFailureReason#1073
sumeruchat merged 2 commits into
masterfrom
fix/SDK-470-authfailurereason-debug-string

Conversation

@sumeruchat

Copy link
Copy Markdown
Contributor

What

AuthFailureReason is an Int-backed @objc enum, so logging an instance prints a raw number. This makes it conform to CustomDebugStringConvertible so logs show the case name.

Changes

  • Add a CustomDebugStringConvertible extension mapping each case to its name.
  • Switch is exhaustive with no default, so a future case fails to compile until labeled.
  • Add a unit test covering all 11 cases.

Impact

  • Breaking changes: None. Additive only, public API and raw values unchanged.
  • Dependencies: None.
  • Performance: None.

Testing

How to test:

  1. Run ./agent_test.sh AuthTests.
  2. testAuthFailureReasonDebugDescriptions passes for all 11 cases.
  3. String(reflecting: AuthFailureReason.authTokenExpired) returns "authTokenExpired".

Jira: https://iterable.atlassian.net/browse/SDK-470

AuthFailureReason is an Int-backed @objc enum, so logging an instance
prints a raw number. Conform to CustomDebugStringConvertible so logs
show the case name instead. The switch is exhaustive with no default,
so adding a future case fails to compile until its label is added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.60%. Comparing base (3ac2f02) to head (cf8e2e8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1073      +/-   ##
==========================================
+ Coverage   71.58%   71.60%   +0.01%     
==========================================
  Files         113      114       +1     
  Lines        9438     9462      +24     
==========================================
+ Hits         6756     6775      +19     
- Misses       2682     2687       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

case authTokenMissing
}

extension AuthFailureReason: CustomDebugStringConvertible {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already solve this exact problem for IterableInAppContentType and IterableInAppTriggerType in InAppPersistence.swift using CustomStringConvertible and description, with a comment explaining why it's needed for @objc enums.

Should we stay consistent and use CustomStringConvertible + description here too?

Both protocols technically work for String(describing:) thanks to the fallback chain, but description is the right semantic for output customers will see in their AuthDelegate logs, and it matches the existing convention in this SDK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, and the InAppPersistence precedent is useful context. Keeping CustomDebugStringConvertible here since SDK-470 asks for it specifically. It still covers the customer path: print(reason) and "\(reason)" go through String(describing:), which falls back to debugDescription, so AuthDelegate logs show the case name. Updated the test (your other comment) to assert String(describing: reason) so it guards that path.

Comment thread tests/unit-tests/AuthTests.swift Outdated
]

expectedDescriptions.forEach { reason, description in
XCTAssertEqual(reason.debugDescription, description)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is asserting debugDescription against the same strings we just hardcoded in the switch, so it can't fail in a meaningful way.
The bug we're fixing is that print(reason) or "\(reason)" shows AuthFailureReason(rawValue: 0) instead of the case name.

Can we switch this to XCTAssertEqual("\(reason)", description) (or String(describing: reason)) so the test actually covers the customer-facing logging path?

That way if someone changes the protocol in the future and breaks String(describing:), this test catches it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Switched the assertion to String(describing: reason) so it covers the print(reason) / "\(reason)" path instead of debugDescription directly.

Assert the customer-facing logging output instead of debugDescription
directly. print(reason) and "\(reason)" resolve through String(describing:),
which falls back to the enum debugDescription, so this guards the case-name
output customers see in AuthDelegate logs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sumeruchat sumeruchat merged commit 6ece5b4 into master Jun 12, 2026
15 checks passed
@sumeruchat sumeruchat deleted the fix/SDK-470-authfailurereason-debug-string branch June 12, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants